from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer
from user.models import Account, Friends, Files
from django.db.models import Q

class UserSerializer(ModelSerializer):
    class Meta:
        model = Account
        exclude = ('password','first_name','last_name','is_staff','is_active','user_permissions','is_superuser','last_login','groups')


class FriendSerializer(ModelSerializer):
    userToFriend = SerializerMethodField()
    friendToUser = SerializerMethodField()

    def get_userToFriend(self,data):
        #查询朋友的信息
        queryset = Account.objects.filter(id=data.friend_id).first()
        userInfoList = UserSerializer(queryset).data
        return userInfoList

    def get_friendToUser(self,data):
        #查询用户的信息
        queryset = Account.objects.filter(id=data.user_id).first()
        userInfoList = UserSerializer(queryset).data
        return userInfoList

    class Meta:
        model = Friends
        fields = "__all__"


class FileSerializer(ModelSerializer):
    class Meta:
        model = Files
        fields = "__all__"